(function(global, Yo, YoPages){
	var Section = Yo.Section;
	var User = Yo.User;
	var Utils = Yo.Utils;

	// main page
	YoPages.initPages.push(function(){
		// user
		var user = User.getFromCookie();
		if(user){
			User.set(user);
		}else{
			User.remove();
			$.get(Yo.host + '/wx/user/logout');
		}
		YoPages.showUser(user);

		// page interceptors
		Section.addInter(/(user\-index|order\-pay)/, function(page){
			// login first
			var user = User.get();
			if(user)
				return true;

			Section.userLoginView = page;
			Section.go('user-login', true);
			return false;
		});
	});

	YoPages.showUser = function(user){
		if(!user || !user.nickname){
			Yo.role('login').hide();
			Yo.role('logout').show();

			$('.user-name').text('');
			$('.user-header').attr('src', Yo.host + 'wx/ind/img/userheader.jpg');
		}else{
			Yo.role('login').show();
			Yo.role('logout').hide();

			$('.user-name').text(user.nickname);
			$('.user-header').attr('src', user.headurl);
		}
	};

})(this, Yo, YoPages);